﻿using Quartz;
using Quartz.Impl;
using QuartzDemo.Jobs;
using System.Threading.Tasks;
namespace QuartzDemo
{
    class Program
    {
        //调度器
        public static IScheduler scheduler;
        //调度器工厂
        public static ISchedulerFactory factory;
        static void Main(string[] args)
        {
            QuzrtzJob();
        }
        static async void QuzrtzJob()
        {
            //创建一个调度器
            factory = new StdSchedulerFactory();
            scheduler = await factory.GetScheduler();

            //创建一个任务
            IJobDetail job = JobBuilder.Create<TestJob>().WithIdentity("job1", "group1").Build();

            //创建一个触发器
            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("trigger1", "group1")
                .WithCronSchedule("0/5 * * * * ?")     //5秒执行一次
                .Build();

            //4、将任务与触发器添加到调度器中
            await scheduler.ScheduleJob(job, trigger);
            //5、开始执行
            await scheduler.Start();
            Console.ReadKey();
        }
    }
}
